package com.leetcode.List;

/**
 * 合并两个有序链表，emmmm这个题确实有点简单啊。。
 */
public class Leetcode21 {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) {
        ListNode head = new ListNode(-99999);
        ListNode p1 = l1;
        ListNode p2 = l2;
        ListNode p = head;
        while (p1 != null && p2 != null) {
            ListNode node;
            if (p1.val < p2.val) {
                 node = new ListNode(p1.val);
                 p1 = p1.next;
            } else {
                 node = new ListNode(p2.val);
                 p2 = p2.next;
            }
            p.next = node;
            p = p.next;
        }

        if (p1 != null) {
            p.next = p1;
        }
        if (p2 != null) {
            p.next = p2;
        }
        return head.next;
    }

}
